package com.nurun.cacheimageloader.util;

import java.io.IOException;
import java.io.InputStream;
import java.net.URI;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import com.nurun.cacheimageloader.AbstractImageDownloader;

public class ImageFileStreamDecoder {

    private final URI uri;
    private final AbstractImageDownloader abstractImageDownloader;

   
    public ImageFileStreamDecoder(URI uri, AbstractImageDownloader abstractImageDownloader) {
        this.uri = uri;
        this.abstractImageDownloader = abstractImageDownloader;
    }

    public Bitmap decode() throws IOException {
        InputStream imageStream = abstractImageDownloader.getStream(uri);
        try {
            return BitmapFactory.decodeStream(imageStream, null, null);
        } finally {
            imageStream.close();
        }
    }
}